<?php
namespace App\Http\Resources;

use App\Http\Resources\BaseResource;
use App\Http\Models\User;

class OrderResource extends BaseResource
{
    protected $first_uid;
    protected $second_uid;
    protected $first_arr = array();
    protected $second_arr = array();
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $userinfo = User::find($this->uid);
        $info = json_decode($userinfo->info);
        $this->second_uid = $this->up_uid;
        return [
            'uid'=>$this->uid,
            'up_uid'=>$this->up_uid,
            'shop_id'=>$this->shop_id,
            'price'=>$this->price,
            'phone'=>$this->phone,
            'status'=>$this->status,
            'name'=>$this->name,
            'phone'=>$this->phone,
            'wechat'=>$this->wechat,
            'avatarUrl'=>$info->avatarUrl,
            $this->mergeWhen($this->second_uid ,function(){
                $up_shop_user = ShopUser::where('uid',$this->second_uid)->where('shop_id',$this->shop_id)->first();
                $this->second_arr['second_up_uid'] = $up_shop_user->up_uid;
                $this->first_uid = $up_shop_user->up_uid;
                return array_merge($this->second_arr, $this->first_arr);
            })
            
        ];
    }
}